package edu.nf.exam.dao.impl;

import edu.nf.exam.dao.ExamPaperInfoDao;
import edu.nf.exam.dao.ExamPaperResultInfoDao;
import edu.nf.exam.entity.ExamPaperResultInfo;
import edu.nf.exam.util.MyBatisUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

/**
 * @Author : QYM
 * @create 2021/6/17
 * 试卷结果表--接口实现类
 */
public class ExamPaperResultInfoDaoImpl implements ExamPaperResultInfoDao {
    /**
     * 添加
     * @param examPaperResultInfo
     * @return
     */
    @Override
    public int add(ExamPaperResultInfo examPaperResultInfo) {
        SqlSession sqlSession = MyBatisUtil.getSqlSession(true);
        int r = sqlSession.getMapper(ExamPaperResultInfoDao.class).add(examPaperResultInfo);
        sqlSession.close();
        return r;
    }

    /**
     * 查询
     * @param examPaperResultInfo
     * @return
     */
    @Override
    public List<ExamPaperResultInfo> select(ExamPaperResultInfo examPaperResultInfo) {
        SqlSession sqlSession = MyBatisUtil.getSqlSession(true);
        List<ExamPaperResultInfo> list = sqlSession.getMapper(ExamPaperResultInfoDao.class).select(examPaperResultInfo);
        sqlSession.close();
        return list;
    }

    /**
     * 分页查询
     * @param userName
     * @param examPaperName
     * @param levelName
     * @param subjectName
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Override
    public List<ExamPaperResultInfo> selectByPage(String userName, String examPaperName, String levelName,String subjectName, Integer pageNum, Integer pageSize) {
        SqlSession sqlSession = MyBatisUtil.getSqlSession(true);
        List<ExamPaperResultInfo> list = sqlSession.getMapper(ExamPaperResultInfoDao.class).selectByPage(userName, examPaperName, levelName,subjectName, pageNum, pageSize);
        sqlSession.close();
        return list;
    }

    /**
     * 根据试卷ID查询成绩名次
     * @param examPaperId
     * @return
     */
    @Override
    public List<ExamPaperResultInfo> selectRankByExamPaperId(Integer examPaperId) {
        SqlSession sqlSession = MyBatisUtil.getSqlSession(true);
        List<ExamPaperResultInfo> list = sqlSession.getMapper(ExamPaperResultInfoDao.class).selectRankByExamPaperId(examPaperId);
        sqlSession.close();
        return list;
    }
}
